package com.li.springbootproject.controller.spring;

import com.li.springbootproject.service.spring.SpringService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 2021/12/29 21:24
 */
@RestController
@RequestMapping("/test")
public class SpringController {

    private static final Logger logger = LoggerFactory.getLogger(SpringController.class);

    @Autowired
    private SpringService springService;

    @Autowired
    private ApplicationContext applicationContext;


    @RequestMapping("/one")
    public void testOne(HttpServletRequest request, HttpServletResponse response) throws IOException {
        springService.testOne(request, response);
    }

    @RequestMapping("/two")
    public void testTwo(HttpServletRequest request, HttpServletResponse response) throws IOException {
        springService.testTwo(request, response);
    }

    @RequestMapping("/three")
    public void testThree(HttpServletRequest request, HttpServletResponse response) throws IOException {
        springService.testThree(request, response);
    }

    /**
     * 使用 PersonBean
     *
     * @param request  request
     * @param response response
     */
    @RequestMapping("/four")
    public void testFour(HttpServletRequest request, HttpServletResponse response) {
        springService.testFour();
    }

    /**
     * 关闭 SpringBoot 服务
     *
     * @param request  request
     * @param response response
     */
    @RequestMapping("/close")
    public void testFive(HttpServletRequest request, HttpServletResponse response) {
        SpringApplication.exit(applicationContext);
    }

    /**
     * 调用 starter 中的内容
     *
     * @param request  request
     * @param response response
     */
    @RequestMapping("/six")
    public void testSix(HttpServletRequest request, HttpServletResponse response) {
        springService.testSix();
    }

}
